package com.text.day2_1;

public class User {
    private String name;
    private int age;

    public User() {
    }

    public User(String name, int age) {
        this.setAge(age);
        this.setName(name);
//        this.name = name;
//        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name.length() > 3 && name.length() < 10)
            this.name = name;
        else
            System.out.println("长度要大于3小于10");
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {    //  给一个外部访问的方法，并控制输入
        if (age < 1 || age > 200)
            System.out.println("年龄非法");
        else
            this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

}
